﻿using System.Collections.Generic;

namespace SubhadraSolutions.Sharp.Utils.Collections.Generic
{
    /// <summary>
    /// The CompositeFilter class.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class CompositeFilter<T> : IFilter<T>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="CompositeFilter{T}"/> class.
        /// </summary>
        public CompositeFilter()
        {
            this.InnerFilters = new List<IFilter<T>>();
        }

        /// <summary>
        /// Gets or sets the inner filters.
        /// </summary>
        /// <value>
        /// The inner filters.
        /// </value>
        public List<IFilter<T>> InnerFilters
        {
            get; set;
        }

        /// <summary>
        /// Shoulds the filter.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns></returns>
        public bool ShouldFilter(T obj)
        {
            foreach (var filter in this.InnerFilters)
            {
                if (filter.ShouldFilter(obj))
                {
                    return true;
                }
            }

            return false;
        }
    }
}
